import Cookies from 'js-cookie'
import { Navigate, useLocation } from 'react-router-dom'

/**
 * 鉴权是否登录
 * @param param0 
 * @returns 
 */
const AuthRouter = ({
    component,
}: {
    component: any
}) => {
    const token = Cookies.get('pai_token')
    const location = useLocation()

    return token ? (
        component
    ) : (
        <Navigate to="/login" replace state={{ from: location }}></Navigate>
    )
}

export default AuthRouter
